package com.xinggq.pay.service.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * Swagger配置类
 * @author xinggq
 * @date 2025/01/20
 */
@Configuration
public class SwaggerConfig {

    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("支付服务API文档")
                        .description("提供支付相关的接口文档，包括统一支付、退款等功能")
                        .version("1.0.0")
                )
                .servers(List.of(
                        new Server().url("http://localhost:8099/pay-service").description("本地开发环境"),
                        new Server().url("https://test-api.example.com/pay-service").description("测试环境"),
                        new Server().url("https://api.example.com/pay-service").description("生产环境")
                ))
                .components(new Components()
                        .addSecuritySchemes("X-App-Id", new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY)
                                .in(SecurityScheme.In.HEADER)
                                .name("X-App-Id")
                                .description("应用ID，用于标识调用方应用")
                        )
                );
    }
}